//package.require("$util.HashMap");

appConfig.i18n = new HashMap();

$AppConfig.prototype.getI18N=function(sKey){
	return this.i18n.get(sKey);
}

$ClassLoader.prototype.loadI18N=function(QName) { 
   var suffix = "_" + appConfig.getLocale();
   try{
 	  var loaded = this.loadJS(QName+suffix);
 	  if(!loaded){
 		 throw new Error("Can't load:\n "+QName+suffix+",\n will try:\n "+QName);
 	  }
 	  return true;
   }catch(e){
 	  //alert(e.description);
 	  this.loadJS(QName);
 	  return true;
   }
}

function $importI18N(names){$import(names, "i18n");}

function i18n(key,args,bundle,locale){
	return appConfig.getI18N(key);
}

function getSubstMessage(text,args){
	var msg = text;
	if(args instanceof Array){
		for(var i=0;i<args.length;i++){
			/**
			 var re = new RegExp("{"+i+"}","g");
			 msg = msg.replace(re,args[i]);
			**/
			msg = msg.replace("{"+i+"}",args[i]);
		}
	}
	//the others not set in args;
	msg = msg.replace(/({\d+})+/g,"");
	return msg;
}

function getSubstMessage2(text,args){
	var msg = text;
	if(args && args.length>0){
		msg = args[0];
		var matchs = msg.match(/(${.+})+/g);
		if( matchs!=null && matchs.length>0 ){
			for(var i=0;i<matchs.length;i++){
				var key = matchs[i].substring(2,matchs[i].length-1);
				msg = msg.replace(matchs[i],args[key]);
			}
		}
	}
	//the others not set in args;
	msg = msg.replace(/(${.+})+/g,"");
	return msg;
}           

/*
if( typeof(I18N)=="undefined" ) I18N =  appConfig.i18n;
	I18N.put("event.ondblclick","雙擊");
	I18N.put("event.onclick",	"單擊");
	I18N.put("event.onblur",	"失去焦點");

if( typeof(CONSTANTS)=="undefined" ) CONSTANTS =  appConfig.constants;
	CONSTANTS.put("message.container","_msgCantainer");
	CONSTANTS.put("message.event.hide","ondblclick");

*/